const sqlite3 = require('sqlite3').verbose();

// 创建数据库连接对象
const db = new sqlite3.Database('book.db', (err) => {
  if (err) {
    console.error('Failed to connect to SQLite database:', err.message);
    return;
  }
  console.log('Connected to SQLite database.');
  // 查询数据库中的所有表名
  db.all("SELECT name FROM sqlite_master WHERE type='table'", [], (err, rows) => {
    if (err) {
      console.error('Error fetching table names:', err.message);
      return;
    }

    // 打印表名
    if (rows.length === 0) {
      console.log('No tables found in the database.');
    } else {
      rows.forEach((row) => {
        console.log('Table name:', row.name);
      });
    }
  });
});

module.exports = db;